home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / util / libs / MMULib.lha / MMULib / Lib_Sources / mu_service.asm < prev    next >
Encoding:
Assembly Source File  |  1998-10-04  |  4.9 KB  |  144 lines

  1. ;*************************************************************************
  2. ;** mmu.library                                                         **
  3. ;**                                                                     **
  4. ;** a system library for arbitration and control of the MC68K MMUs      **
  5. ;**                                                                     **
  6. ;** © 1998 THOR-Software, Thomas Richter                                **
  7. ;** No commercial use, reassembly, modification without prior, written  **
  8. ;** permission of the authors.                                          **
  9. ;** Including this library in any commercial software REQUIRES a        **
  10. ;** written permission and the payment of a small fee.                  **
  11. ;**                                                                     **
  12. ;** This is an internal header file, do not depend on anything here.    **
  13. ;** Use the official include files.                                     **
  14. ;** Distributed only for the mmu.library development group for private  **
  15. ;** use.                                                                **
  16. ;**                                                                     **
  17. ;**---------------------------------------------------------------------**
  18. ;** Block: Service routines                                             **
  19. ;*************************************************************************
  20.  
  21. ;FOLD Includes
  22.         include mu_lib.i
  23.         include INC:exec_lib.asm
  24.         include INC:macros.asm
  25. ;ENDFOLD
  26. ;FOLD Defines
  27. memf_clear      =       16
  28. ;ENDFOLD
  29.  
  30.         section main_code,code
  31.  
  32. ;FOLD AllocAligned
  33. ;*************************************************
  34. ;** AllocAligned                                **
  35. ;** Allocate d0 bytes of type d1, aligned to a0 **
  36. ;** boundaries                                  **
  37. ;** return NULL on failure or the memory block  **
  38. ;*************************************************
  39.         xdef AllocAligned
  40. AllocAligned:
  41.         saveregs d2-d4/a6
  42.  
  43.         move.l a0,d2            ;alignment present?
  44.         beq .fail
  45.  
  46.         move.l mulib_SysBase(a6),a6
  47.         subq.l #1,d2            ;reduce
  48.         move.l d1,d4            ;keep type
  49.         move.l d0,d3            ;saveback size
  50.         bclr #memf_clear,d1     ;MEMF_CLEAR doesn't matter anyways
  51.         add.l d2,d0             ;bytes + alignment - 1
  52.         jsr AllocMem(a6)        ;get the memory
  53.         tst.l d0
  54.         beq.s .exit             ;on failure
  55.         jsr Forbid(a6)          ;does not alter the registers
  56.         move.l d0,a1            ;keep it
  57.         move.l d3,d1            ;restore bytesize
  58.         add.l d2,d0             ;address plus alignment
  59.         add.l d2,d1
  60.         not.l d2
  61.         and.l d0,d2             ;align to next boundary
  62.         move.l d1,d0
  63.         jsr FreeMem(a6)         ;release it
  64.  
  65.         move.l d3,d0            ;bytesize
  66.         move.l d2,a1            ;location
  67.         jsr AllocAbs(a6)        ;allocate it
  68.  
  69.         jsr Permit(a6)          ;does not alter registers
  70.  
  71.         tst.l d0                ;worked?
  72.         beq.s .fail             ;pass thru failure
  73.  
  74.         move.l d2,d0            ;location in d2
  75.         btst #memf_clear,d4     ;clear it ?
  76.         beq.s .exit
  77.                                 ;here: Yes, please
  78.         move.l d2,a0
  79.         moveq #0,d1             ;Clear
  80.         sub.l a1,a1
  81.         moveq #0,d2
  82.         sub.l a6,a6
  83.         adda.l d3,a0            ;Poiner BEHIND the memory
  84.  
  85.         lsr.l #1,d3
  86.         bcc.s .nobyte
  87.         move.b d1,-(a0)         ;One byte at the end?
  88. .nobyte:
  89.         lsr.l #1,d3
  90.         bcc.s .noword
  91.         move.w d1,-(a0)
  92. .noword:
  93.         lsr.l #1,d3
  94.         bcc.s .nolong
  95.         move.l d1,-(a0)
  96. .nolong:
  97.         lsr.l #1,d3
  98.         bcc.s .noquad
  99.         movem.l d1/d2,-(a0)
  100. .noquad:
  101.         lsr.l #1,d3
  102.         bcc.s .no2quad
  103.         movem.l d1/d2/a1/a6,-(a0)
  104. .no2quad:
  105.         do
  106.          subq.l #1,d3
  107.          bcs.s .exit
  108.          movem.l d1/d2/a1/a6,-(a0)
  109.          movem.l d1/d2/a1/a6,-(a0)
  110.         loop.s
  111. .fail:
  112.         moveq #0,d0
  113. .exit:
  114.         loadregs
  115.         rts
  116. ;ENDFOLD
  117. ;FOLD SubSuper
  118. ;*************************************************
  119. ;** SubSuper                                    **
  120. ;** Execute a subroutine - address on stack     **
  121. ;** in supervisor code                          **
  122. ;** the routine must exit with RTE              **
  123. ;** Preserve all registers                      **
  124. ;*************************************************
  125.         xdef SubSuper
  126. SubSuper:
  127.         movem.l a4-a6,-(a7)
  128.  
  129.         lea _CallSuper(pc),a5
  130.         move.l mulib_SysBase(a6),a6
  131.         move.l a7,a4
  132.         jsr Supervisor(a6)
  133.  
  134.         lea $c(a7),a7                   ;remove register dump
  135.         move.l (a7)+,(a7)               ;Remove address from stack
  136.         rts
  137. _CallSuper:
  138.         move.l $10(a4),-(a7)            ;Jump in here
  139.         movem.l (a4),a4-a6              ;restore registers
  140.         rts                             ;jump in
  141. ;ENDFOLD
  142.  
  143.  
  144.